//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;

namespace OpenLS.Chart.UI
{
    class PieChartLayout: ChartLayout
    {
                private readonly Dictionary<int, Bounds> indexToBounds = new Dictionary<int, Bounds>();

                public PieChartLayout(PieSeries s)
        {
            double total = 0;
            Dictionary<int, Bounds> temp = new Dictionary<int, Bounds>();
            foreach (NumericValue value in s.Values.NumericValues)
            {
                double v = Math.Abs(value.Value);
                double newTotal = total + v;
                temp.Add(value.Index, Bounds.Create(total, newTotal));
                total = newTotal;
            }
            foreach (KeyValuePair<int, Bounds> p in temp)
            {
                indexToBounds.Add(p.Key, Bounds.Create(p.Value.Low/total, p.Value.High/total));
            }
        }
                public override double GetZ(int seriesIndex)
                {
                    return 0;
                }

        #region INumericChartDisplayInformation Members

        public override int Count
        {
            get { return 1; }
        }

        public override Bounds GetBounds(int index, int seriesIndex)
        {
            return indexToBounds[index];
        }

        public override Bounds GetBounds(NumericValue value, Series series, double floor)
        {
            return GetBounds(value.Index, series.Index);
        }

        #endregion


        internal override Bounds GetXBounds(Bounds xBounds, int seriesIndex, int seriesCount)
        {
            throw new NotImplementedException();
        }
    }

}
